/**
 * Sencha GXT 3.1.0 - Sencha for GWT Copyright(c) 2007-2014, Sencha, Inc. licensing@sencha.com
 * http://www.sencha.com/products/gxt/license/
 */
package gttp.nspa.client.adm;

import gttp.nspa.client.adm.activity.IBillingList;
import gttp.nspa.client.adm.activity.ICustomerForm;
import gttp.nspa.client.adm.activity.ICustomerList;
import gttp.nspa.client.adm.place.BillingListPlace;
import gttp.nspa.client.adm.ui.BillingList;
import gttp.nspa.client.adm.ui.CustomerForm;
import gttp.nspa.client.adm.ui.CustomerList;
import gttp.nspa.client.adm.ui.NsShell;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.gwt.place.shared.PlaceController;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.place.shared.PlaceHistoryMapper;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;

public class NsModule extends AbstractGinModule {

    protected void configure() {
        bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
        bind(PlaceHistoryMapper.class).to(NsPlaceHistoryMapper.class).in(Singleton.class);
        bind(ActivityMapper.class).to(NsActivityMapper.class).in(Singleton.class);
        bind(NsShell.class).in(Singleton.class);

        bind(IBillingList.class).to(BillingList.class).in(Singleton.class);
        bind(ICustomerForm.class).to(CustomerForm.class).in(Singleton.class);
        bind(ICustomerList.class).to(CustomerList.class).in(Singleton.class);
    }

    @Provides
    @Singleton
    PlaceController getPlaceController(EventBus eventBus) {
        return new PlaceController(eventBus);
    }

    @Provides
    @Singleton
    PlaceHistoryHandler getHistoryHandler(PlaceController placeController,
                                          PlaceHistoryMapper historyMapper,
                                          EventBus eventBus) {
        PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(historyMapper);
        historyHandler.register(placeController, eventBus, new BillingListPlace(true));
        return historyHandler;
    }

    @Provides
    @Singleton
    public ActivityManager getActivityManager(ActivityMapper mapper, EventBus eventBus) {
        return new ActivityManager(mapper, eventBus);
    }
}
